package com.example.demo53.ui.Temperation;


import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;


import com.example.demo53.R;
import com.gcssloop.widget.ArcMaskCircilarView;
import com.gcssloop.widget.ArcSeekBar;

public class uniLight extends AppCompatActivity {
    private TextView mProgressText1;
    private SeekBar dseek1;
    private TextView tv_dseek1;
    private ImageView light_icon1;
    private ArcSeekBar mArcSeekBar1;
    private int gray = -8355712;
    private int color_icon= gray;
    private ArcMaskCircilarView arcMaskCircilarView ;
    private int mcolor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.uni_light_controller);
        mProgressText1 = findViewById(R.id.txt_progress2);
        mArcSeekBar1 = findViewById(R.id.arc_seek_bar2);
        mArcSeekBar1.setArcColors(R.array.arc_colors_custom2);

        light_icon1=findViewById(R.id.icon_light2);



//set value(max and min) of seekbar
// ---------------mArcSeekBar的最大值最小值设置
        mArcSeekBar1.setMaxValue(100);
        mArcSeekBar1.setMinValue(0);
        //setEngry(mArcSeekBar.getProgress());

        listening();

//        findViewById(R.id.btn_0).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mArcSeekBar.setProgress(0);
//            }
//        });
//
//        findViewById(R.id.btn_90).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mArcSeekBar.setProgress(90);
//            }
//        });
    }

    public  void listening() {

        //灯泡总开关
        light_icon1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (color_icon == gray) {
                    light_icon1.setColorFilter(color_icon);
                    color_icon = -1;
                    //send data of lighting on


                } else if (color_icon == -1) {

                    light_icon1.setColorFilter(color_icon);
                    color_icon = gray;
                }
            }
        });



        mArcSeekBar1.setOnProgressChangeListener(new ArcSeekBar.OnProgressChangeListener() {
            @Override
            public void onProgressChanged(ArcSeekBar seekBar, int progress, boolean isUser) {
                setEngry();
//            int color1=seekBar.getColor();
//            Color.colorToHSV(color1, hsv);
//            mHue = color1;
//            mSat = hsv[1];
//            mVal =  hsv[2];
//
//        //    mcolor=Color.HSVToColor(new float[]{mHue, mSat, mVal});
//            arcMaskCircilarView.setColor(Color.HSVToColor(new float[]{mHue, mSat, mVal}));


            }

            @Override
            public void onStartTrackingTouch(ArcSeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(ArcSeekBar seekBar) {
                setEngry();
            }

            @Override
            public void onColorListening(ArcSeekBar seekBar, int mArcColors) {

            }


        });
    }
    private void setEngry() {
        mProgressText1.setText( +(int)(mArcSeekBar1.getLastProgress2()) + " %");
    }
}
